

/*
*
*	监听整个页面滚动事件 , 如果比较列表达到浏览器顶部, 则改为固定定位
*
*/

const countDistanceTop = function() {
	let EA_ThirdClass = document.getElementsByClassName('EA_ThirdClass')[0];
	let E_T_First_line = document.getElementsByClassName('E_T_First_line')[0];
	let E_T_More = document.getElementsByClassName('E_T_More')[0];
	let CountDistanceTop = EA_ThirdClass.offsetTop-document.documentElement.scrollTop;
	if (CountDistanceTop<=1) {
		if ((E_T_First_line.className.search('fixed')==-1)) {
			setTimeout(function(){
				addClassName(E_T_More,'pause');
			},500);
		}
		addClassName(E_T_First_line,'fixed');
		delClassName(E_T_First_line,'absolute');
		addClassName(E_T_More,'E_T_More_in');

	}else if (!(E_T_First_line.className.search('fixed')==-1)&&CountDistanceTop>1) {
		addClassName(E_T_First_line,'absolute');
		delClassName(E_T_First_line,'fixed');
		delClassName(E_T_More,'pause');		

			setTimeout(function(){
				delClassName(E_T_More,'E_T_More_in');
			},500);

	}

}



/*
*
*监听页面有效宽度, 显示和隐藏"有效列表"
*
*/
const countScreenAvailWidth = function() {

	let E_T_Second_Line = document.getElementsByClassName('E_T_Second_Line')[0];
	let E_More_options = document.getElementsByClassName('E_More_options')[0];

	let availWidth = document.documentElement.clientWidth;
	if (availWidth<=1200) {

		addClassName(E_T_Second_Line,'hide');
		delClassName(E_More_options,'hide');

	}
	if (availWidth>1201) {

		addClassName(E_More_options,'hide');
		delClassName(E_T_Second_Line,'hide');
	}
	// console.log(availWidth);
}


addEventListener(window,'resize',throttle(countScreenAvailWidth),50);


// 设置文字移动互斥信号量
const arr =[0,0,0,0]
const E_F_titles = document.getElementsByClassName('E_F_title');
 	//偷懒: 文字移动
 	const temp = function(i){

		// console.log(E_F_titles[i]);
		arr.forEach((item,index)=>{
			if ((i==index)&&(item==0)) {
				arr[index]=1;
				// console.log(arr);
				// console.log(index);
				addClassName(E_F_titles[i],'MoveTitle');
			}else if ((arr[index]==1)&&(i!=index)) {
				arr[index]=0;
				delClassName(E_F_titles[index],'MoveTitle');
			}
		});
	
 	}



/*
*
*监听整个页面滚动事件, 移动橙色指示下标 , 遮罩层文字移动
*
*/



const arrays = [];
const MoveIndexSubscript = function(arrays) {
	let EA_SecondClass = document.getElementsByClassName('EA_SecondClass')[0];
	let EA_ThirdClass = document.getElementsByClassName('EA_ThirdClass')[0];
	let EA_fifth = document.getElementsByClassName('EA_fifth')[0];
	let EA_Sixth = document.getElementsByClassName('EA_Sixth')[0];
	let EA_FourthClass = document.getElementsByClassName('EA_FourthClass')[0];

	let E_T_side = document.getElementsByClassName('E_T_side')[0];
	let CountDistanceTop = EA_ThirdClass.offsetTop-document.documentElement.scrollTop;
	let availWidth = document.documentElement.clientWidth;

	let ScondHeight = EA_SecondClass.offsetTop-document.documentElement.scrollTop;
	let ThirdHeight = EA_ThirdClass.offsetTop-document.documentElement.scrollTop;
	let Fourthheight = EA_FourthClass.offsetTop-document.documentElement.scrollTop;
	let FifthHeight = EA_fifth.offsetTop-document.documentElement.scrollTop;
	let SixHeight = EA_Sixth.offsetTop-document.documentElement.scrollTop;

 	// console.log(CountDistanceTop);
 	if( (CountDistanceTop<200)&&(CountDistanceTop>0) ){
		if(arr[0]==0){
			temp(0);

		}
 	}else if( (CountDistanceTop<-500)&&(CountDistanceTop>-700) ) {
		if(arr[1]==0){
			temp(1);

		}
 	}else if( (CountDistanceTop<-1200)&&(CountDistanceTop>-1400) ) {
		if(arr[2]==0){
			temp(2);

		}
 	}else if( (CountDistanceTop<-1800)&&(CountDistanceTop>-2100) ) {
		if(arr[3]==0){
			temp(3);

		}
 	}

	if ((CountDistanceTop>120)&&(arrays.length!=0)) {
		addClassName(E_F_titles[1],'MoveTitle');
		arrays.forEach((item,index)=>{
			delClassName(E_T_side,arrays[index]);
			arrays.shift();

		});

	}

	if (((Fourthheight<120)&&FifthHeight>=120)&&(Fourthheight>-2600)) {
		if(availWidth<=1200){
			addClassName(E_T_side,'E_T_side_to_more');
			arrays.push('E_T_side_to_more');
		}else {
			addClassName(E_T_side,'E_T_side_to_EAplay');
			arrays.push('E_T_side_to_EAplay');	
			delClassName(E_T_side,'E_T_side_to_PlayList');	
		}
	}


 	if((FifthHeight<120)&&(availWidth>1200)&&(SixHeight>120)){
			addClassName(E_T_side,'E_T_side_to_PlayList');
			arrays.push('E_T_side_to_PlayList');	
	 		arrays.forEach((item,index)=>{
	 			if(item!='E_T_side_to_PlayList'){
					delClassName(E_T_side,arrays[index]);
					arrays.splice(index,1);
	 			}

			});	
 	}


 	if ((SixHeight<120)&&(availWidth>1200)) {
			addClassName(E_T_side,'E_T_side_to_wenda');
			arrays.push('E_T_side_to_wenda');
 	}





}


/*
*
* 导航列表 点击跳转
*
*/

const GoTo = function () {
	let EA_SecondClass = document.getElementsByClassName('EA_SecondClass')[0];
	let EA_ThirdClass = document.getElementsByClassName('EA_ThirdClass')[0];
	let EA_fifth = document.getElementsByClassName('EA_fifth')[0];
	let EA_Sixth = document.getElementsByClassName('EA_Sixth')[0];

	let ScondHeight = EA_SecondClass.offsetTop;
	let ThirdHeight = EA_ThirdClass.offsetTop;
	let FifthHeight = EA_fifth.offsetTop;
	let SixHeight = EA_Sixth.offsetTop;


	let Comparison_plan = document.getElementsByClassName('Comparison_plan')[0];
	let E_T_S_goto_2 = document.getElementsByClassName('E_T_S_goto_2')[0];
	let E_T_S_goto_3 = document.getElementsByClassName('E_T_S_goto_3')[0];
	let E_T_S_goto_4 = document.getElementsByClassName('E_T_S_goto_4')[0];

	addEventListener(Comparison_plan,'click',()=>{
		scrollAnimation(document.documentElement.scrollTop,ScondHeight);
		// window.scrollTo(0, ScondHeight);
	});
	addEventListener(E_T_S_goto_2,'click',()=>{
		scrollAnimation(document.documentElement.scrollTop,ThirdHeight);
		// window.scrollTo(0, ThirdHeight);
	});
	addEventListener(E_T_S_goto_3,'click',()=>{
		scrollAnimation(document.documentElement.scrollTop,FifthHeight);
		// window.scrollTo(0, FifthHeight);
	});
	addEventListener(E_T_S_goto_4,'click',()=>{
		scrollAnimation(document.documentElement.scrollTop,SixHeight);
		// window.scrollTo(0, SixHeight);
	});

}


function scrollAnimation(currentY, targetY) {
 // 获取当前位置方法
 // const currentY = document.documentElement.scrollTop || document.body.scrollTop

 // 计算需要移动的距离
 let needScrollTop = targetY - currentY
 let _currentY = currentY
 setTimeout(() => {
   // 一次调用滑动帧数，每次调用会不一样
   const dist = Math.ceil(needScrollTop / 10)
   _currentY += dist
   window.scrollTo(_currentY, currentY)
   // 如果移动幅度小于十个像素，直接移动，否则递归调用，实现动画效果
   if (needScrollTop > 10 || needScrollTop < -10) {
     scrollAnimation(_currentY, targetY)
   } else {
     window.scrollTo(_currentY, targetY)
   }
 }, 1)
}




	//考虑性能 暂时关闭
const ScrollEvent = function() {

	countDistanceTop();
	MoveIndexSubscript(arrays);
}

addEventListener(window,'scroll',throttle(ScrollEvent,80));




/*
*
* 控制问答板块 , 中的显示与隐藏
*
*/

const AnswerTheQuestion = function() {
	// 用作五个问答的互斥信号量
	let arrays = [0,0,0,0,0];

	let question_answer = document.querySelectorAll(".question_answer > div");
	let Open_all = document.getElementsByClassName('Open_all')[0];
	let E_S_span_1 =document.getElementsByClassName('E_S_span_1')[0];
	let E_S_span_2 =document.getElementsByClassName('E_S_span_2')[0];

	//储存"问题"元素
	let questions = [];

	//储存"回答"元素
	let answers = [];

	//显示/隐藏 全部互斥信号量
	let isopen = 0;

	question_answer.forEach((item,index)=>{
		if (index%2==0) {
			questions.push(item);
		}else{
			answers.push(item);
		}
	});

	let ShowOrHide = function (i) {
		if(arrays[i]==0){
			arrays[i]=1;
			delClassName(answers[i],'hide');
		}else {
			arrays[i]=0;
			addClassName(answers[i],'hide');
		}
		if (arrays[i]==0) {
			delClassName(questions[i].children[0],'rotate90');
		}else {
			addClassName(questions[i].children[0],'rotate90');
		}
	}

	let ShowOrHide_1 = function () {
		ShowOrHide(0);
	}

	let ShowOrHide_2 = function () {
		ShowOrHide(1);
	}

	let ShowOrHide_3 = function () {
		ShowOrHide(2);
	}

	let ShowOrHide_4 = function () {
		ShowOrHide(3);
	}

	let ShowOrHide_5 = function () {
		ShowOrHide(4);
	}

	let ShowOrHide_6 = function () {
		if(isopen==0){
			arrays.forEach((item,index)=>{
				if(item==0){
					switch(index) {
					   case 0: {
					      ShowOrHide_1();
					      break;
					   }
					   case 1: {
					      ShowOrHide_2();
					      break;
					   }
					   case 2: {
					      ShowOrHide_3();
					      break;    
					   }
					   case 3: {
					      ShowOrHide_4();
					      break;
					   }  
					   case 4: {
					      ShowOrHide_5();
					      break;
					   }  
					}
				}
			});
			isopen=1;
			addClassName(E_S_span_1,'hide');
			delClassName(E_S_span_2,'hide');
		}else {
			arrays.forEach((item,index)=>{
				if(item==1){
					switch(index) {
					   case 0: {
					      ShowOrHide_1();
					      break;
					   }
					   case 1: {
					      ShowOrHide_2();
					      break;
					   }
					   case 2: {
					      ShowOrHide_3();
					      break;    
					   }
					   case 3: {
					      ShowOrHide_4();
					      break;
					   }  
					   case 4: {
					      ShowOrHide_5();
					      break;
					   }  
					}
				}
			});
			isopen=0;
			addClassName(E_S_span_2,'hide');
			delClassName(E_S_span_1,'hide');
		}
	}



	addEventListener(questions[0],'click',ShowOrHide_1);
	addEventListener(questions[1],'click',ShowOrHide_2);
	addEventListener(questions[2],'click',ShowOrHide_3);
	addEventListener(questions[3],'click',ShowOrHide_4);
	addEventListener(questions[4],'click',ShowOrHide_5);
	addEventListener(Open_all,'click',ShowOrHide_6);
}
















































/*
*	等到页面加载完毕 , 再调用其方法
*/
	
window.onload=function(){

	countScreenAvailWidth();
	let temp = document.body.scrollHeight-1000;
	// window.scrollTo(0, temp);
	AnswerTheQuestion();
	GoTo();
}